<template>
  <div>
    <el-form :key="interfaceInfo.id" v-for="(interfaceInfo, index) in interfaceData"
             label-position="right" :inline="true"
    >
      <el-form-item :label="interfaceInfo.name">
        <el-input v-model="interfaceInfo.url" disabled></el-input>
      </el-form-item>
      <el-form-item label="模板：">
        <el-input v-model="interfaceInfo.username" disabled></el-input>
      </el-form-item>
      <el-switch
        v-if="(roleCheck('msg-switch') && type==1) || (roleCheck('card-switch') && type==2) || (roleCheck('inter-msg-switch') && type==5)"
        class="switch"
        active-text="开启"
        inactive-text="关闭"
        :active-value="0"
        :inactive-value="1"
        @change="()=>toggleInterface(interfaceInfo)"
        v-model="interfaceInfo.status">
      </el-switch>
    </el-form>
  </div>
</template>

<script>
  import {form} from '@/build';
  import {systemInterfaceGetApi,systemInterfaceUpdateStatus} from '@/services/api/system';
  export default {
    name: "interface-form",
    props:['type'],
    mixins:[form],
    data(){
      return{
        interfaceData: [],
        apiType: this.type
      }
    },

    methods:{
      toggleInterface(row){
        const {status,id,apiType} = row
        systemInterfaceUpdateStatus({id,status,apiType}).then(([result,data])=>{
          if(result){
            console.log(data)
          }
        })
      },
    },
    mounted() {
      this.bindGet(systemInterfaceGetApi, 'interfaceData',{
        sendingData:{apiType: this.apiType},
        action: 'getInterface'
      });
      this.getAll();
    },

  }
</script>

<style scoped>

</style>
